<template>
    <div>
        <div id="head">
            <p>搜索历史</p>
            <van-icon id="right" name="delete-o" />
        </div>
        <div id="body">
            <div v-for="(item,index) in list" :key="index">
                {{item.title}}
            </div>
        </div>
    </div>
</template>

<script>
import sha1 from "sha1";
export default {
  data() {
    return {
        list: [],
        news:{}
    }
  },
  mounted () {
    this.getNewsList();
  },
  methods: {
    getNewsList() {
      var app_id='A6107876068110';
      var now = Date.now();
      var appKey = sha1(app_id+"UZ"+"58EBAF35-D1F8-D16D-C10F-3EFF74B31665"+"UZ"+now)+"."+now
      let url="https://d.app3c.cn/mcm/api/SearchHistory";
      return this.axios({
        "method":"get",
        "url":url,
       "headers": {
        "X-APICloud-AppId": app_id,
        "X-APICloud-AppKey":appKey
      }
      }).then((res)=>{
        this.list=res.data;
      })
    },
    addNews() {
      var app_id='A6107876068110';
      var now = Date.now();
      var appKey = sha1(app_id+"UZ"+"58EBAF35-D1F8-D16D-C10F-3EFF74B31665"+"UZ"+now)+"."+now
      let url="https://d.app3c.cn/mcm/api/SearchHistory"
      return this.axios({
        "method":"post",
        "url":url,
       "headers": {
        "X-APICloud-AppId": app_id,
        "X-APICloud-AppKey":appKey
      },
      "data":{
        title:value,
      }
      }).then(res=>{
        if(res.status==200){
          alert("插入成功");
          this.getNewsList();
        }      
        else
          alert("插入失败");
      })
    }
  },
}
</script>

<style lang="scss" scoped>
    #head{
        width: 100%;
        margin-top: 2.5vw;
        margin-bottom: 4vw;
        display: flex;
        p{
            font-weight: bold;
            font-size: 5vw;
            padding-left: 3vw;
        }
        #right{
            left: 68vw;
            font-size: 5vw;
            padding-top: 1vw;
        }
    }
    #body{
        width: 90%;
        margin-top: 4vw;
        margin-bottom: 3vw;
        display: flex;
        flex-wrap: wrap;
        div{
            background: rgba(245, 244, 244, 0.99);
            width:fit-content;
            width:-webkit-fit-content;
            width:-moz-fit-content;
            border-radius: 10%;
            font-size: 4vw;
            margin-left: 7vw;
            margin-bottom: 3vw;
        }
    }
</style>